//
//  Fraction.m
//  OC03_属性_点语法
//
//  Created by dllo on 16/2/26.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "Fraction.h"


#pragma mark - init
@implementation Fraction
- (instancetype)initWithNumerator:(NSInteger)numerator denominator:(NSInteger)denominator{
    
    self = [super init];
    if (self) {
        _numerator =numerator;
        _denominator = denominator;
    }
    return self;
}

#pragma mark - 构造器
+ (instancetype)fractionWithNumerator:(NSInteger)numerator denominator:(NSInteger)denominator{
    
    return [[Fraction alloc] initWithNumerator:numerator denominator:denominator];
}

#pragma mark - 功能
- (Fraction *)plusWithFraction:(Fraction *)frac{
    
    // 新的分数分子.
    NSInteger newNum = self.numerator * frac.denominator + self.denominator * frac.numerator;
    
    // 新的分数分母.
    NSInteger newDeno = self.denominator * frac.denominator;
    
    // 创建一个分数对象.
    Fraction *newFrac = [Fraction fractionWithNumerator:newNum denominator:newDeno];
    
    // 返回分数.
    return newFrac;
    
}
@end
